//
//  WJCBaseViewController.m
//  花絮
//
//  Created by WJC mac on 2021/10/6.
//

#import "WJCBaseViewController.h"
#import "WJCDefine.h"
#import "UIView+WJCBaseXibDeploy.h"
@interface WJCBaseViewController ()

@end

@implementation WJCBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor whiteColor];
}
-(void)viewDidLayoutSubviews{
    if (self.deployModel) {
        [self loadAllSubViewsWithView:self.view];
    }
}
-(void)setDeployModel:(id)deployModel{
    _deployModel = deployModel;
    if (deployModel) {
        [self loadAllSubViewsWithView:self.view];
    }
}
-(void)loadAllSubViewsWithView:(UIView*)view{
    for (UIView *v in view.subviews) {
        if (v.modelDeploy.length>0) {
            [self setModelWithView:v];
        }
        if (v.subviews.count>0) {
            [self loadAllSubViewsWithView:v];
        }
    }
}
-(void)setModelWithView:(UIView*)v{
    NSArray *arr = [v.modelDeploy componentsSeparatedByString:@","];
    NSString *str;
    for (NSString *st in arr) {
        if ([st containsString:@"."]) {
            NSArray *subArr = [st componentsSeparatedByString:@"."];
            id ob = self.deployModel;
            for (NSString *s in subArr) {
                
                if ([ob checkIsExistPropertyWithInstance:ob verifyPropertyName:s andLogAllProperty:NO]) {
                    ob = [ob valueForKey:s];
                }
            }
            if([ob isKindOfClass:[NSString class]]){
                str =ob;
            }
        }else{
            if ([self.deployModel isKindOfClass:[NSDictionary class]]) {
                if ([self.deployModel valueForKey:st]&&[[self.deployModel valueForKey:st] isKindOfClass:[NSString class]]) {
                    str =[self.deployModel valueForKey:st];
                }
//                str =[NSString stringWithFormat:@"%@",[self.deployModel valueForKey:st]];
            }
       else if ([self.deployModel checkIsExistPropertyWithInstance:self.deployModel verifyPropertyName:st andLogAllProperty:NO]) {
            if ([[self.deployModel valueForKey:st] isKindOfClass:[NSString class]]) {
                str =[self.deployModel valueForKey:st];
            }
        }
        }
    }
        if ([v isKindOfClass:[UILabel class]]) {
            ((UILabel*)v).text = [NSString stringWithFormat:@"%@%@%@",v.headDeploy?(UILabel*)v.headDeploy:@"",str,v.footDeploy?(UILabel*)v.footDeploy:@""];
        }else if ([v isKindOfClass:[UIButton class]]) {
            [((UIButton*)v) setTitle:[NSString stringWithFormat:@"%@%@%@",v.headDeploy?(UILabel*)v.headDeploy:@"",str,v.footDeploy?(UILabel*)v.footDeploy:@""] forState:UIControlStateNormal];
        }else if ([v isKindOfClass:[UIImageView class]]) {
            
            [((UIImageView*)v) fc_setImageWithURL:str placeholder:[WJCDeployModel getDeployWithDeployKey:WJCDeployHeadImage] completed:nil];
        }else if ([v isKindOfClass:[UITextField class]]) {
            ((UITextField*)v).text = [NSString stringWithFormat:@"%@%@%@",v.headDeploy?(UILabel*)v.headDeploy:@"",str,v.footDeploy?(UILabel*)v.footDeploy:@""];
        }else if ([v isKindOfClass:[UITextView class]]) {
            ((UITextView*)v).text = [NSString stringWithFormat:@"%@%@%@",v.headDeploy?(UILabel*)v.headDeploy:@"",str,v.footDeploy?(UILabel*)v.footDeploy:@""];
        }
        
    ///后续持续完善,
//    else{
//        if (self.idBlock) {
//            ///设置额外视图样式
//            self.idBlock(self);
//        }
//
//    }
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
